<%@page import="java.util.Date"%>
<%@page import="service.PutCache"%>
<%@page import="model.NewsRecent"%>
<%@page import="java.util.ArrayList"%>
<%@page import="service.Link"%>
<%@page import="service.Util"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.Format"%>
<%@page import="model.News"%>
<%@page import="com.googlecode.objectify.Query"%>
<%
	request.setCharacterEncoding("UTF-8");
	response.setContentType("text/html; charset=utf-8");
	News news = (News) request.getAttribute("news");
	response.setCharacterEncoding("utf-8");
	Format formatter = new SimpleDateFormat("MM / yyyy");
	Format formatter1 = new SimpleDateFormat("dd");
	Query<News> list = (Query<News>) request.getAttribute("list");
	Query<News> list1 = (Query<News>) request.getAttribute("list1");
	
	String title = news.getTitle().getValue();
	String description = Util.cutDescription(news.getContent().getValue());
	String keyword = news.getCategory();
	if(news.getTag().size()>0)
	{
		for(int i=0;i<news.getTag().size();i++)
		{
			keyword += ","+news.getTag().get(i);
		}
	}
	
	ArrayList<NewsRecent> newLess = PutCache.getCacheNews("newLess"+news.getAlias());
	ArrayList<NewsRecent> oldLess = PutCache.getCacheNews("oldLess"+news.getAlias());
	
	Date dates = new Date(news.getDate());
	String dedate = (dates.getYear()+1900)+"-"+(dates.getMonth()+1)+"-"+dates.getDate();
%>
<%@ page language="java" import="java.util.Enumeration"
	pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<jsp:include page="layout/header.jsp">
	<jsp:param name="title" value="<%=title %>" />
	<jsp:param name="description" value="<%=description %>" />
	<jsp:param name="keywords" value="<%=keyword %>" />
	<jsp:param name="name" value="<%=news.getThumb() %>" />
	<jsp:param name="link" value="detail" />
	<jsp:param name="date" value="<%=dedate %>" />
</jsp:include>

<div class="body">
	<div class="detail">
		<ul class="itemscope breadcrumb" itemprop="breadcrumb">
			<li><a itemprop="url" href="/"><span itemprop="name">Home</span></a></li>
			<li><a itemprop="url"
				href="/<%=Link.linkCate() %>/<%=news.getCategoryAlias()%>"><span><%=news.getCategory()%></span></a></li>
			<li style="padding-top: 5px;float: right;">
				<!-- AddThis Button BEGIN -->				
				<div class="addthis_toolbox addthis_default_style ">
				<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
				<a class="addthis_button_tweet" tw:via="tonghoptin"></a>
			
				<a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
				<a class="addthis_counter addthis_pill_style"></a>
				</div>
                <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4d6f3cdb1d190d60"></script>
                <!-- AddThis Button END -->
			</li>	
		</ul>
		<div class="clear"></div>
		<div class="date">
			<div class="month"><%=formatter.format(news.getDate())%></div>
			<span><%=formatter1.format(news.getDate())%></span>
		</div>
		<h1><%=news.getTitle().getValue()%></h1>
		<div class="content">
			<%=news.getContent().getValue()%>
		</div>
		<p class="tags">
			<%
				if(news.getTag().size()>0)
				{
					for(int i=0;i<news.getTag().size();i++)
					{
			%>
					<a href="/<%=Link.linkTag() %>/<%=Util.convertAlias(news.getTag().get(i)) %>">, <%=news.getTag().get(i) %></a>
			<%
					}
				}
			%>
		</p>
		<p class="copyright"> <a href="/">Home</a> <a href="javascript:history.back()">Quay lại</a> <a target="_blank" rel="nofollow" href="<%=news.getSource().getValue()%>">Xem tin bài gốc</a> </p>
		
		<div id="fb-root"></div>
		<script
			src="http://connect.facebook.net/en_US/all.js#appId=165471683512060&amp;xfbml=1"></script>
		<fb:comments
			href="<%=Link.domain()+"/"+Link.linkDetail()+"/"+news.getAlias() %>"
			width="740"></fb:comments>
	</div>
	<div class="relate">
		<%
			if (oldLess != null && oldLess.size() > 0) {
		%>
		<span>Tin mới hơn</span>
		<ul>
			<%
				for (int i=0;i<oldLess.size();i++) {
			%>
			<li><a href="/<%=Link.linkDetail() %>/<%=Util.convertAlias(oldLess.get(i).getTitle())%>"><%=oldLess.get(i).getTitle() %></a>
			</li>
			<%
				}
			%>
		</ul>
		<%
			}
		%>
		<%
			if (newLess != null && newLess.size() > 0) {
		%>
		<span>Tin cũ hơn</span>
		<ul>
			<%
				for (int i=(newLess.size()-1);i>=0;i--) {
			%>
			<li><a href="/<%=Link.linkDetail() %>/<%=Util.convertAlias(newLess.get(i).getTitle())%>"><%=newLess.get(i).getTitle()%></a>
			</li>
			<%
				}
			%>
		</ul>
		<%
			}
		%>
	</div>
	<div class="clear"></div>
</div>

<jsp:include page="layout/footer.jsp"></jsp:include>